﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace Lm.Common.ExtensionMethods
{
    public static class  DropdownListExt
    {
        public static void SetSelectedValue(this DropDownList ddl, string value)
        {
            var itemList = (from ListItem i in ddl.Items where i.Value == value select i);
            if (itemList.Count() > 0)
            {
                ddl.SelectedIndex = ddl.Items.IndexOf(itemList.First());
            }
        }
        public static void SetSelectedText(this DropDownList ddl, string text)
        {
            var itemList = (from ListItem i in ddl.Items where i.Text == text select i);
            if (itemList.Count() > 0)
            {
                ddl.SelectedIndex = ddl.Items.IndexOf(itemList.First());
            }
        }
    }
}
